package Generic;

public class Individual implements Comparable<Individual>{
	
	private Genotype gtype;
	private Phenotype ptype;
	private double fitness;
	private int age;
	private int id;
	private int pidx,pidy;
	
	private static int nextId = 0;
	
	public Individual()
	{
		gtype=null;
		ptype=null;
		fitness=-1.0;
		setAge(0);
		id = nextId++;
		pidx = -1;
		pidy = -1;
	}
	
	public Individual(Individual individual)
	{
		gtype=individual.gtype.copy();
		ptype=null;
		fitness=-1.0;
		setAge(0);
		id = nextId++;
		pidx = individual.id;
		pidy = -1;
	}
	
	public void setGenotype(Genotype gtype)
	{
		this.gtype=gtype;
	}
	
	public String toString()
	{
		String str="";
		
		str+=gtype!=null?("Genotype: "+gtype.toString()):"";
		str+=ptype!=null?("   Phenotype: "+ptype.toString()):"";
		str+=fitness!=-1?("   Fitness: "+fitness):"";
		str+="   Id: "+id;
		str+=pidx!=-1?("   ParentX: "+pidx):"";
		str+=pidy!=-1?("   ParentY: "+pidy):"";
		
		return str;
	}

	public Genotype getGenotype() {
		return gtype;
	}

	public void setPhenotype(Phenotype ptype) {
		this.ptype=ptype;
	}

	public Phenotype getPhenotype() {
		return ptype;
	}

	public void setFitness(double fitness) {
		this.fitness = fitness;
	}

	public void incrementAge() {
		setAge(getAge() + 1);
	}

	public double getFitness() {
		return fitness;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int getParentX() {
		return pidx;
	}

	public void setParentY(int parentX) {
		pidy = parentX;
	}

	public int compareTo(Individual ind) {
		
		return (int) Math.signum(fitness-ind.fitness);
	}
}
